package com.ztstudy.poi.Java_Map_demos.jihe.list_;

import java.util.LinkedList;
import java.util.List;

public class list_exercise1 {
    public static void main(String[] args) {

        //List list = new ArrayList();
        //List list = new Vector();
        List list = new LinkedList();

        list.add(new book("java", "james", 88));
        list.add(new book("phyton", "james2", 58));
        list.add(new book("c++", "james3", 98));
        list.add(new book("三国演义", "罗贯中", 188));

        sort(list);


        for (Object o : list){
            System.out.println(o.toString());
        }


    }

    public static void sort(List list){
        for (int i=0;i<list.size();i++){
            for (int j=0;j<list.size()-i-1;j++){
                book b1 = (book) list.get(j);
                book b2 = (book) list.get(j+1);

                if (b1.getPrice()<b2.getPrice()){
                    list.set(j,b2);
                    list.set(j+1,b1);
                }
            }
        }
    }
}

